package edu.pku.group6.dao;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import edu.pku.group6.entities.*;


/**
 * Data access object (DAO) for domain model class TSmsservice.
 * 
 * @see edu.pku.group6.dao.TSmsservice
 * @author MyEclipse Persistence Tools
 */

public class SMSServiceDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(SMSServiceDAO.class);

	// property constants
	public static final String NAME = "name";

	public static final String USERID = "userid";

	public static final String AUDITING = "auditing";

	public void save(SMSService transientInstance) {
		log.debug("saving SMSService instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(SMSService persistentInstance) {
		log.debug("deleting SMSService instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public SMSService findById(java.lang.Integer id) {
		log.debug("getting SMSService instance with id: " + id);
		try {
			SMSService instance = (SMSService) getSession().get(
					"edu.pku.group6.entities.SMSService", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(SMSService instance) {
		log.debug("finding SMSService instance by example");
		try {
			List results = getSession().createCriteria(
					"edu.pku.group6.entities.SMSService").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding SMSService instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from SMSService as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByName(Object name) {
		return findByProperty(NAME, name);
	}

	public List findByUserid(Object userid) {
		return findByProperty(USERID, userid);
	}

	public List findByAuditing(Object auditing) {
		return findByProperty(AUDITING, auditing);
	}

	public List findAll() {
		log.debug("finding all SMSService instances");
		try {
			String queryString = "from SMSService";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public SMSService merge(SMSService detachedInstance) {
		log.debug("merging SMSService instance");
		try {
			SMSService result = (SMSService) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(SMSService instance) {
		log.debug("attaching dirty SMSService instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(SMSService instance) {
		log.debug("attaching clean SMSService instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}